import {ref, watchEffect} from 'vue'

export const curTheme = ref(localStorage.getItem('curTheme') == null ? 'light' : localStorage.getItem('curTheme'))


watchEffect(() => {
    document.querySelector('html').dataset.theme = curTheme.value
})

export function toggleTheme() {
    if (curTheme.value == 'light') {
        //     切换为黑夜主题
        localStorage.setItem('curTheme', 'dark')
        curTheme.value = 'dark'
    } else {
        //     切换为明亮主题
        localStorage.setItem('curTheme', 'light')
        curTheme.value = 'light'
    }
}
